<!--
 * @Description: 左侧菜单
 * @Author: lixx
 * @Date: 2025-09-24 15:01:13
 * @LastEditTime: 2025-10-09 10:51:29
 * @LastEditors: lixx
-->
<template>
  <el-aside :width="width">
    <el-menu
      active-text-color="#ffd04b"
      background-color="#545c64"
      text-color="#fff"
      :collapse="isCollapse"
      :collapse-transition="false"
      :default-active="route.path"
    >
      <h3 v-show="!isCollapse">通用后台管理系统</h3>
      <h3 v-show="isCollapse">后台</h3>
      <el-menu-item
        v-for="item in noChildren"
        :key="item.path"
        :index="item.path"
        @click="handleMenu(item)"
      >
        <!-- <el-icon><setting /></el-icon> -->
        <component class="icons" :is="item.icon"></component>
        <span>{{ item.label }}</span>
      </el-menu-item>
      <el-sub-menu
        v-for="item in hasChildren"
        :key="item.path"
        :index="item.path"
         @click="handleMenu(item)"
      >
        <template #title>
          <common-icons class="icons" :type="item.icon"></common-icons>
          <span>{{ item.label }}</span>
        </template>
        <el-menu-item-group>
          <el-menu-item
            v-for="subItem in item.children"
            :key="subItem.path"
            :index="subItem.path"
          >
            <common-icons class="icons" :type="subItem.icon"></common-icons>
            <span>{{ subItem.label }}</span>
          </el-menu-item>
        </el-menu-item-group>
      </el-sub-menu>
    </el-menu>
  </el-aside>
</template>

<script setup>
import { ref, computed } from "vue";
import { useAllDateStore } from "../stores";
import { useRoute ,useRouter } from "vue-router";
const store = useAllDateStore();
//  const list = ref([
//   {
//     path: "/home",
//     name: "home",
//     label: "首页",
//     icon: "House",
//     url: "home",
//   },
//   {
//     path: "/product",
//     name: "product",
//     label: "商品管理",
//     icon: "House",
//     url: "product",
//   },
//   {
//     path: "/user",
//     name: "user",
//     label: "用户管理",
//     icon: "User",
//     url: "User",
//   },
//   {
//     path: "other",
//     label: "其他",
//     icon: "location",
//     children: [
//       {
//         path: "/page1",
//         name: "page1",
//         label: "页面1",
//         icon: "setting",
//         url: "Page1",
//       },
//       {
//         path: "/page2",
//         name: "page2",
//         label: "页面2",
//         icon: "setting",
//         url: "Page2",
//       },
//     ],
//   },
// ]);

const list = computed(() => store.state.menuList);
console.log('list<insert>',list)
const noChildren = computed(() => list.value.filter((o) => !o.children));
const hasChildren = computed(() => list.value.filter((o) => o.children));


const isCollapse = computed(() => {
  return store.state.isCollapse;
});
const width = computed(() => {
  return store.state.isCollapse ? "64px" : "180px";
});

const route = useRoute()
const router = useRouter()
console.log('route+++',route)
console.log('router+++',router)
const handleMenu = (val)=>{
  router.push(val.name)
  store.selectMenu(val)
}
</script>
<style lang="less" scoped>
.el-aside {
  background: #545c64;
  height: 100%;
}
.el-menu {
  border-right: none;
  //background: #545c64;
  color: #fff;
  text-align: center;
  h3 {
    line-height: 48px;
    color: #fff;
  }
}
.icons {
  width: 18px;
  height: 18px;
  margin-right: 5px;
}
</style>
